package org.ruanjj.multithread;

public class CommunicationTest {
    public static void main(String[] args) {
        Communication communication = new Communication();

        Thread t1 = new Thread(communication,"甲");
        Thread t2 = new Thread(communication,"乙");

        t1.start();
        t2.start();
    }
}

class Communication implements Runnable{
    private static int ticket = 0;
    @Override
    public void run() {
        while(true){
            synchronized (this){
                notify();
                if(ticket < 100){
                    ticket++;
                    System.out.println(Thread.currentThread().getName()+":"+ticket);
                }else{
                    break;
                }
                try {
                    wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
